import java.util.Scanner;


class Counter {
    public volatile int flag = 0;
}


class Test {


    public static void main(String[] args) {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            while (counter.flag == 0) {
                // do nothing
            }
            System.out.println("循环结束!");
        });
        Thread t2 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("输⼊⼀个整数:");
            counter.flag = scanner.nextInt();
        });
        t1.start();
        t2.start();
    }
}
// 执⾏效果
// 当⽤⼾输⼊⾮0值时, t1 线程循环不会结束. (这显然是⼀个 bug)